package com.ruoyi.mybatchscheduling.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mybatchscheduling.domain.Algorithm;
import com.ruoyi.mybatchscheduling.service.IAlgorithmService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 算法信息Controller
 * 
 * @author chenxin
 * @date 2024-01-27
 */
@RestController
@RequestMapping("/algorithm")
public class AlgorithmController extends BaseController
{
    @Autowired
    private IAlgorithmService algorithmService;

    /**
     * 查询算法信息列表
     */
    @RequiresPermissions("mybatchscheduling:algorithm:list")
    @GetMapping("/list")
    public TableDataInfo list(Algorithm algorithm)
    {
        startPage();
        List<Algorithm> list = algorithmService.selectAlgorithmList(algorithm);
        return getDataTable(list);
    }

    /**
     * 导出算法信息列表
     */
    @RequiresPermissions("mybatchscheduling:algorithm:export")
    @Log(title = "算法信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Algorithm algorithm)
    {
        List<Algorithm> list = algorithmService.selectAlgorithmList(algorithm);
        ExcelUtil<Algorithm> util = new ExcelUtil<Algorithm>(Algorithm.class);
        util.exportExcel(response, list, "算法信息数据");
    }

    /**
     * 获取算法信息详细信息
     */
    @RequiresPermissions("mybatchscheduling:algorithm:query")
    @GetMapping(value = "/{算法名称}")
    public AjaxResult getInfo(@PathVariable("算法名称") String 算法名称)
    {
        return success(algorithmService.selectAlgorithmBy算法名称(算法名称));
    }

    /**
     * 新增算法信息
     */
    @RequiresPermissions("mybatchscheduling:algorithm:add")
    @Log(title = "算法信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Algorithm algorithm)
    {
        return toAjax(algorithmService.insertAlgorithm(algorithm));
    }

    /**
     * 修改算法信息
     */
    @RequiresPermissions("mybatchscheduling:algorithm:edit")
    @Log(title = "算法信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Algorithm algorithm)
    {
        return toAjax(algorithmService.updateAlgorithm(algorithm));
    }

    /**
     * 删除算法信息
     */
    @RequiresPermissions("mybatchscheduling:algorithm:remove")
    @Log(title = "算法信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{算法名称s}")
    public AjaxResult remove(@PathVariable String[] 算法名称s)
    {
        return toAjax(algorithmService.deleteAlgorithmBy算法名称s(算法名称s));
    }
}
